package pt.chukaku.gtgb;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		log("onCreate");
		
		findViewById(R.id.scan).setOnClickListener(bScan);
		// findViewById(R.id.bookmarks).setOnClickListener(bBookmarks);
		findViewById(R.id.extra).setOnClickListener(bExtra);
	}

	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				String contents = intent.getStringExtra("SCAN_RESULT");

				Bundle bundle = new Bundle();
				bundle.putString("isbn", contents);
				Intent resultIntent = new Intent(this, ResultActivity.class);
				resultIntent.putExtras(bundle);
				startActivity(resultIntent);
			} else if (resultCode == RESULT_CANCELED) {
				// Handle cancel
			}
		}
	}

	public final Button.OnClickListener bScan = new Button.OnClickListener() {
		public void onClick(View v) {
			Intent intent = new Intent("com.google.zxing.client.android.SCAN");
			intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
			startActivityForResult(intent, 0);
		}
	};

	public final Button.OnClickListener bExtra = new Button.OnClickListener() {
		public void onClick(View v) {
			log("nExtra");
			Bundle bundle = new Bundle();
			bundle.putString("isbn", "9781421519180");
			Intent resultIntent = new Intent(getApplicationContext(),
					ResultActivity.class);
			resultIntent.putExtras(bundle);
			startActivity(resultIntent);
		}
	};
	
	private void log(String position) {
		Log.d("GTG", "MainActivity: " + position);
	}
}